package com.oriental.manage.controller.specially;

import com.oriental.manage.core.exception.BusiException;
import com.oriental.manage.core.paging.Pagination;
import com.oriental.manage.core.response.ResponseDTO;
import com.oriental.manage.core.utils.Validate;
import com.oriental.manage.model.specially.SpeciallyMchntBaseInfoDelete;
import com.oriental.manage.service.specially.SpeciallyMchntBaseInfoDeleteService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by jinxin on 2017/4/20.
 *商户信息删除
 */
@Controller
@Slf4j
@RequestMapping("specialMerchant/baseInfoDelete")
public class SpeciallyMchntBaseInfoDeleteController {

    @Autowired
    SpeciallyMchntBaseInfoDeleteService speciallyMchntBaseInfoDeleteService;

    @RequestMapping("/init")
    public String init(){
        return "specially/searchSpeciallyMchntBaseInfoDelete";
    }

    @RequestMapping("/toDelete")
    public String toUpload(){
        return "specially/uploadSpeciallyMchntBaseInfoDelete";
    }

    @RequestMapping("/toDetail")
    public String toDetail(){
        return "specially/speciallyMchntBaseInfoDeleteDetail";
    }

    @RequestMapping("/search")
    @ResponseBody
    public ResponseDTO<Pagination<SpeciallyMchntBaseInfoDelete>> search(Pagination<SpeciallyMchntBaseInfoDelete> pagination, SpeciallyMchntBaseInfoDelete speciallyMchntBaseInfoDelete) {
        ResponseDTO<Pagination<SpeciallyMchntBaseInfoDelete>> responseDTO=new ResponseDTO<>();
        try{
                speciallyMchntBaseInfoDeleteService.search(speciallyMchntBaseInfoDelete,pagination);
                responseDTO.setSuccess(true);
                responseDTO.setObject(pagination);
        }catch(Exception e){
            log.error("查询失败", e);
            responseDTO.setSuccess(false);
            responseDTO.setMsg("企业商户删除信息查询失败");
        }
        return responseDTO;
    }

//
//    @RequestMapping("/deleteData")
//    @ResponseBody
//    protected ResponseDTO<List<SpeciallyMchntBaseInfoDelete>> mchntData(SpeciallyMchntBaseInfoDelete speciallyMchntBaseInfoDelete) {
//        ResponseDTO<List<SpeciallyMchntBaseInfoDelete>> responseDTO = new ResponseDTO<>();
//        log.info("企业商户删除初上报详情:{}", speciallyMchntBaseInfoDelete);
//        try {
//            List<SpeciallyMchntBaseInfoDelete> speciallyMchntBaseInfoDeleteList=speciallyMchntBaseInfoDeleteService.recordSpeciallyMchntBaseInfoDelete(speciallyMchntBaseInfoDelete);
//            responseDTO.setSuccess(true);
//            responseDTO.setObject(speciallyMchntBaseInfoDeleteList);
//        } catch (Exception e) {
//            log.error("编辑上报初始化失败", e);
//            responseDTO.setSuccess(false);
//            responseDTO.setMsg(e.getMessage());
//        }
//        return responseDTO;
//    }

    @RequestMapping("/upload")
    @ResponseBody
    protected ResponseDTO<String> update(ResponseDTO<String> responseDTO,@RequestBody SpeciallyMchntBaseInfoDelete speciallyMchntBaseInfoDelete) {
        log.info("企业商户信息删除:{}", speciallyMchntBaseInfoDelete);
        try {
            Validate.validateObject(speciallyMchntBaseInfoDelete);
            speciallyMchntBaseInfoDeleteService.insertSpeciallyMchntBaseInfoDelete(speciallyMchntBaseInfoDelete,responseDTO);
        } catch (BusiException e) {
            log.error("参数校验失败", e.getMessage());
            responseDTO.setSuccess(false);
            responseDTO.setMsg(e.getMessage());
        }catch (Exception e) {
            log.error("更新失败", e);
            responseDTO.setSuccess(false);
            responseDTO.setMsg("更新失败");
        }
        return responseDTO;
    }

}
